package logic

import (
	"context"
	"user_srv/models"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdatePositionLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdatePositionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdatePositionLogic {
	return &UpdatePositionLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdatePositionLogic) UpdatePosition(in *user.UpdatePositionRequest) (*user.UpdatePositionResponse, error) {
	// todo: add your logic here and delete this line

	var p models.Position
	p.PositionName = in.PositionName
	p.Category = in.Category
	p.Address = in.Address
	p.Salary = float64(in.Salary)
	p.WorkExperience = in.WorkExperience
	p.Graduate = in.Graduate
	p.Info = in.Info
	p.UserId = in.UserId
	p.ID = uint(in.PositionId)

	err := p.UpdatePosition()
	if err != nil {
		logx.Error("修改失败", err)
		return nil, err
	}

	return &user.UpdatePositionResponse{PositionId: int64(p.ID)}, nil
}
